# -*- coding: utf-8 -*-

'''
Created on 2013/11/20

@author: jchchen
'''

from dajaxice.decorators import dajaxice_register
from data.models import Data
from django.utils import simplejson

@dajaxice_register(method='POST', name='data.testGqlGeoptAjax')
def testGqlGeoptAjax(request, minPt):
    queryStr = 'WHERE pt > GEOPT(' + str(minPt['lat']) + ','+ str(minPt['lng']) + ')'
    qry = Data.gql( queryStr )
    resultCount = qry.count();
    pts = []
    for data in qry:
         pts.extend([{'lat':data.pt.lat, 'lng':data.pt.lon}])
    return simplejson.dumps({'result': resultCount, 'pts':pts })